package com.atstudy.other;

/**
 * @version v1.0
 * @description:
 * @author: admin
 * @date: 2022/12/23 16:10
 * @copyright: 博为峰
 */
public class ThreadLocalDemo {
    public static ThreadLocal<Integer> local = new ThreadLocal() {
        @Override
        protected Object initialValue() {
            return 0;
        }
    };

    public static void main(String[] args) {
        new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 3; i++) {
                    local.set(local.get() + 1);
                }
                System.out.println(Thread.currentThread().getName() + "," + local.get());
            }
        }.start();

        new Thread() {
            @Override
            public void run() {
                for (int i = 0; i < 3; i++) {
                    local.set(local.get() + 1);
                }
                System.out.println(Thread.currentThread().getName() + "," + local.get());
            }
        }.start();
    }
}
